package servlet;

import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class GoodsUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int iid =Integer.parseInt(request.getParameter("iid"));
        String type =request.getParameter("type");
        int wid =Integer.parseInt(request.getParameter("wid"));
        String wname =request.getParameter("wname");
        int number=Integer.parseInt(request.getParameter("number"));
        String staff =request.getParameter("staff");

        String sql ="UPDATE inventory SET type=?,wid=?,wname=?,number=?,staff=?WHERE iid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
            ps.setString(1,type);
            ps.setInt(2,wid);
            ps.setString(3,wname);
            ps.setInt(4,number);
            ps.setString(5,staff);
            ps.setInt(6,iid);
            int up = ps.executeUpdate();
            request.getRequestDispatcher("goods.jsp").forward(request, response);

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
